import {
  LoginReturnValue,
  QQLoginCallbackReturnValue,
  QQLoginReturnValue,
  UserSpaceReturnValue,
} from "@/types/login";
import { GeneralReturnValue } from "@/types/general";
import http from "@/utils/axios";

/**
 * 获取验证码
 * @param type 0:登录注册 1:邮箱验证码发送 默认0
 * @returns
 */
export const getVerificationCodeAPI = (type: number) =>
  http<GeneralReturnValue>({
    url: `/checkCode?type=${type}`,
    method: "GET",
  });

/**
 * 发送邮箱验证码
 * @param data 邮箱,图片验证码,图片验证码
 * @returns
 */
export const sendEmailVerificationCodeAPI = (data: {
  email: string;
  checkCode: string;
  type: number;
}) =>
  http<GeneralReturnValue>({
    url: "/sendEmailCode",
    method: "POST",
    data,
  });

/**
 * 注册
 * @param data 邮箱,昵称,密码 只能是数字，字母，特殊字符 8-18位,图片验证码,邮箱验证码
 * @returns
 */
export const registerAPI = (data: {
  email: string;
  nickName: string;
  password: string;
  checkCode: string;
  emailCode: string;
}) =>
  http<GeneralReturnValue>({
    url: "/register",
    method: "POST",
    data,
  });

/**
 * 账号登录
 * @param data 邮箱,md5加密传输,图片验证码
 * @returns
 */
export const loginAPI = (data: {
  email: string;
  password: string;
  checkCode: string;
}) =>
  http<LoginReturnValue>({
    url: "/login",
    method: "POST",
    data,
  });

/**
 * 重置密码
 * @param data 邮箱,md5加密传输,图片验证码,邮箱验证码
 * @returns
 */
export const resetPasswordAPI = (data: {
  email: string;
  password: string;
  checkCode: string;
  emailCode: string;
}) =>
  http<GeneralReturnValue>({
    url: "/resetPwd",
    method: "POST",
    data,
  });

/**
 * 获取用户头像
 * @param userId 用户ID
 * @returns
 */
export const getUserProfileAvatarAPI = (userId: number) =>
  http<any>({
    url: `/getAvatar/${userId}`,
    method: "GET",
  });

/**
 * 获取用户空间
 * @returns
 */
export const getUserSpaceAPI = () =>
  http<UserSpaceReturnValue>({
    url: "/getUseSpace",
    method: "GET",
  });

/**
 * 退出
 * @returns
 */
export const exitAPI = () =>
  http<GeneralReturnValue>({
    url: "/logout",
    method: "GET",
  });

/**
 * 更新用户头像
 * @returns
 */
export const updateUserProfileAvatarAPI = (data: { avatar: string }) =>
  http<GeneralReturnValue>({
    url: "/updateUserAvatar",
    method: "POST",
    data,
  });

/**
 * 修改密码
 * @returns
 */
export const changePasswordAPI = (data: { password: string }) =>
  http<GeneralReturnValue>({
    url: "/updatePassword",
    method: "POST",
    data,
  });

/**
 * QQ登录
 * @param data
 * @returns
 */
export const QQLoginAPI = (data: { callbackUrl: string }) =>
  http<QQLoginReturnValue>({
    url: "/qqlogin",
    method: "POST",
    data,
  });

/**
 * QQ登录回调
 * @param data qq官方回调的code,获取登录信息后端传入的状态码
 * @returns
 */
export const QQLoginCallbackAPI = (data: { code: string; state: string }) =>
  http<QQLoginCallbackReturnValue>({
    url: "/qqlogin/callback",
    method: "POST",
    data,
  });
